package com.chixing.ih.module.programmer.service.Impl;

import com.chixing.ih.module.programmer.mapper.*;
import com.chixing.ih.module.programmer.pojo.Programmer;
import com.chixing.ih.module.programmer.pojo.UserImage;
import com.chixing.ih.module.programmer.pojo.WorkExper;
import com.chixing.ih.module.programmer.pojo.dto.ProgrammerCompareDTO;
import com.chixing.ih.module.programmer.service.IProgrammerCompareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @version 1.0
 * @Author MasterYan
 * @Date 2020/10/7
 * Time: 22:35
 */
@Service
@Transactional
public class ProgrammerCompareServiceImpl implements IProgrammerCompareService {

    @Autowired
    ProgrammerMapper programmerMapper;

    @Autowired
    ImageMapper imageMapper;
    @Autowired
    PersonalSkillMapper personalSkillMapper;
    @Autowired
    PersonalProjectMapper personalProjectMapper;

    @Autowired
    WorkExperMapper workExperMapper;

    @Autowired
    EvaluateMapper evaluateMapper;




    @Override
    public List<ProgrammerCompareDTO> listProgrammer(List<Long> ids) {
        List<ProgrammerCompareDTO> programmerCompareDTOList = new ArrayList<>();
        for (Long id : ids
        ) {
            ProgrammerCompareDTO programmerCompareDTO = new ProgrammerCompareDTO();
            Programmer programmerMapperOne = programmerMapper.getOne(id);
            if (programmerMapperOne != null) {
                programmerCompareDTO.setUserId(programmerMapperOne.getProgrammerId());
                programmerCompareDTO.setNickName(programmerMapperOne.getNickName());
                programmerCompareDTO.setProgrammerCareer(programmerMapperOne.getProgrammerCareer());
                programmerCompareDTO.setProgrammerCompany(programmerMapperOne.getProgrammerCompany());
                programmerCompareDTO.setProgrammerIntroduction(programmerMapperOne.getProgrammerIntroduction());

            }

            UserImage oneByUserId = imageMapper.getOneByUserId(id);
            if (oneByUserId != null)
                programmerCompareDTO.setImageUrl(oneByUserId.getImageUrl());

            List<String> skillNames = personalSkillMapper.getSkillName(id);
            if (skillNames != null)
                programmerCompareDTO.setSkillNames(skillNames);
            List<String> projectTitles = personalProjectMapper.getProjectTitle(id);
            if (projectTitles != null)
                programmerCompareDTO.setProjectTitles(projectTitles);

            Double starRating = evaluateMapper.getStarRating(id);
            if (starRating != null)
                programmerCompareDTO.setStarRating(starRating);

            List<WorkExper> workExpers = workExperMapper.listAll(id);
            if (workExpers != null)
                programmerCompareDTO.setWorkExpers(workExpers);


            programmerCompareDTOList.add(programmerCompareDTO);

        }
        return programmerCompareDTOList;
    }
}
